package com.yundahh.u8c.dao;

import com.yundahh.u8c.config.U8CConfig;
import com.yundahh.u8c.dao.base.U8CBaseDao;
import com.yundahh.u8c.entity.Zzfs;
import com.yundahh.u8c.entity.base.U8CResult;
import com.yundahh.u8c.enums.OperationType;
import com.yundahh.u8c.util.HttpUtils;
import com.yundahh.u8c.util.JsonUtils;

import java.io.IOException;
import java.util.List;

public class ProduceModeDao extends U8CBaseDao {
    public ProduceModeDao(U8CConfig config) {
        super(config);
        this.appendHeader("custdevpclass","nc.api.mm.pub.develop.ZzfsInsert");
    }

    @Override
    public String getApiUrl() {
        return "";
    }

    public U8CResult<Zzfs> send(Zzfs zzfs) throws IOException {
        String s = HttpUtils.sendPost(config.getServerUrl() + "/u8cloud/api/dev/define", headerMap, "[{\"pd_zzfs\":" +JsonUtils.object2Json(zzfs)+"}]");
        U8CResult<Zzfs> zzfsU8CResult = JsonUtils.parseInsert(s, Zzfs.class);
        return zzfsU8CResult;
    }
    public U8CResult<Zzfs> send(String json) throws IOException {
        String s = HttpUtils.sendPost(config.getServerUrl() + "/u8cloud/api/dev/define", headerMap, json);
        U8CResult<Zzfs> zzfsU8CResult = JsonUtils.parseInsert(s, Zzfs.class);
        return zzfsU8CResult;
    }

    public String send(List<Zzfs> list) throws IOException {
        StringBuilder sb=new StringBuilder();
        sb.append("[");
        for (Zzfs zzfs : list) {
            sb.append("{\"pd_zzfs\":");
            sb.append(zzfs);
            sb.append("},");
        }
        //删除末尾的逗号
        sb.deleteCharAt(sb.length()-1);
        sb.append("]");
        String s = HttpUtils.sendPost(config.getServerUrl() + "/u8cloud/api/dev/define", headerMap, sb.toString());
        return s;
    }
}
